package cn.tedu.fresheveryday.controller;

import cn.tedu.fresheveryday.pojo.entity.User;
import cn.tedu.fresheveryday.pojo.vo.ViewHistorySimpleVO;
import cn.tedu.fresheveryday.service.IViewHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@Api(tags = "商品浏览历史模块")
@RequestMapping(path = "/history", produces = "application/json;charset=utf-8")
public class ViewHistoryController {
    @Autowired
    private IViewHistoryService service;

    /**
     * 查询用户的浏览历史
     * @param session
     * @return
     */
    @GetMapping("/select")
    @ApiOperation("查询用户的商品浏览历史")
    public List<ViewHistorySimpleVO> select(HttpSession session) {
        // 获取登录的用户信息
        User user = (User) session.getAttribute("user");

        if (user != null) {
            return service.select(user.getId());
        }

        return null;
    }

}